package com.song.dubbo3consumer;

import com.song.dubbo3.api.Dubbo3TestService;
import com.song.dubbo3.api.MyException;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author SHI YUAN
 * @DATE 2022/2/7 11:57 PM
 * @Version 1.0
 * @Desc
 */
@Slf4j
@RestController
@RequestMapping(path = "/dubbo3")
public class TestController {

    @DubboReference
    private Dubbo3TestService dubbo3TestService;

    @GetMapping(path = "/test/{msg}")
    public Object testDubbo(@PathVariable("msg") String msg){
        try {
            String s = dubbo3TestService.sayHello(msg);
            log.info("[TestController] call dubbo3 {}", s);
            return s;
        }catch (MyException exception){
            log.error("[TestController] error :{}", exception.getMessage(), exception);
            return exception.getMessage();
        }
    }
}
